package com.seeyon.apps.ebs.dao.impl;

import com.seeyon.apps.ebs.dao.AddNewEnumDao;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.log.CtpLogFactory;
import com.seeyon.ctp.util.JDBCAgent;
import org.apache.commons.logging.Log;

import java.util.*;

public class AddNewEnumDaoImpl implements AddNewEnumDao {
    private static final Log log = CtpLogFactory.getLog(AddNewEnumDaoImpl.class);
    @Override
    public Map<String, Object> getMaxEnumSort(Long enumId) {
        String sql = "SELECT CAST(MAX(CAST(ENUMVALUE AS SIGNED)) AS SIGNED) AS enumvalue," +
                "  MAX(SORTNUMBER) AS sortnumber from ctp_enum_item where ref_enumid=:enumId";
        log.info("查询最大排序enum数据sql:"+sql);
        Map<String,Object> params = new HashMap<>();
        params.put("enumId",enumId);
        JDBCAgent jdbcAgent = new JDBCAgent(false,false);
        List<Map<String,Object>> result = new ArrayList<>();
        try {
            result = jdbcAgent.findNamedSql(sql,params);
        } catch (BusinessException e) {
            log.error("查询最大排序enum数据失败",e);
        }finally {
            jdbcAgent.close();
        }
        if (result!=null&& !result.isEmpty()){
            return result.get(0);
        }
        return null;
    }
}
